function checkPeople(string){
    var checkPeopleString = string;
    if(null==checkPeopleString||checkPeopleString.length==0)
    {
        return 'KB';
    }
    var deptworkcode = /^\d{6}$/,
    	deptmobile = /^\d{11}$/;
    var r = checkPeopleString.match(deptworkcode),
        r2 = checkPeopleString.match(deptmobile);
    if(null != r){
    	return 'GH';
    }else if((null != r2)){
    	return 'SJ';
    }else{
    	return 'XM';
    }

}

/**
查询通讯录-条件人员方法
*/
function queryAddressListByName(name){
	 var AddressListInfoHtml = returnAddressListPerson();

	 var isWhoWhoWho = checkPeople(name);
	 var a1 = "";
	 var a2 = "";
	 var a3 = "";
	 if('KB'==isWhoWhoWho){
		 showMsg('warn', '请输入查询内容！');
	 }else{

		 if('GH'==isWhoWhoWho){
			 a1 = name;
		 }else if('SJ'==isWhoWhoWho){
			 a3 = name;
		 }else if('XM'==isWhoWhoWho){
			 a2 = name;
		 }

		 $.ajax({
	         url: CUSTOM_SERVICE_URL + "addressList/queryByPeople",
	         type: "POST",
	         data: {workcode: a1,lastname: a2 ,mobile: a3},
	         success: function (rs) {
	          $(".oaClerkSearch .oaClerkSearch_tbody").empty();
	          var length = rs.length;
	          if(length<1){
	        	  $(".oaClerkSearch").slideUp("500");
                  $(".search-null").slideDown("500");
                  // checktip($('.multiplequerywaybillno'), '无法检索查询结果');
	          }else{
                  $(".search-null").slideUp("500");
                  $(".oaClerkSearch").slideDown("500");
	        	  for (var x = 0; x < length; x++) {
	        		  var picpeoplexy = "pt";
	        		  var peoplesex = rs[x].sex;
	        		  if('女' == peoplesex){
	        			  picpeoplexy = 'wm';
	        		  }

		    		  var $AddressListInfo = $(AddressListInfoHtml.replace("{lastname}",rs[x].lastname).replace("{mobile}",rs[x].mobile)
		    				  .replace("{jobtitle}",rs[x].jobtitle).replace("{workcode}",rs[x].workcode)
		    				  .replace("{departmentname}",rs[x].departmentname)
		    				  .replace("{departmentphone}",rs[x].departmentphone)
		    				  .replace("{picsex}",picpeoplexy)
		    				  );

		              $(".oaClerkSearch .oaClerkSearch_tbody").append($AddressListInfo);
		          }
	          }

	             console.log("渲染人员信息查询方法开始！");


	         },
	         error: function (httpRequest) {
	        	 // $(".oaClerkSearch").slideToggle("500");
	             console.log("渲染人员信息查询方法失败！");
                 showMsg("warn","系统维护中！");
	         }
	     });
	 }

}

/**
查询通讯录-条件部门方法
*/
function queryAddressListByDept(dept,num){
	 var DeptAddressListInfoHtml = returnAddressListDept();
	 var PersonAddressListInfoHtml = returnAddressListPersonDept();
	 $.ajax({
         url: CUSTOM_SERVICE_URL + "addressList/queryByDepartmentcode",
         type: "POST",
         data: {departmentcode: dept},
         success: function (rs) {
        	 console.log("渲染部门信息查询方法开始！");
	          var length = rs.length;
	          deptThreeContent("","","");
	          $(".oaDepartSearch .departAdmin .departAdmin_tbody").empty();
	          $(".oaDepartSearch .childDepart_table .childDepart_tbody").empty();

	          if(length<1){
	        	  // $(".oaDepartSearch").slideToggle("500");
                  $(".oaDepartSearch").slideUp("500");
                  $(".search-null").slideDown("500");
                  // checktip($('.multiplequerywaybillno'), '无法检索查询结果');
	          }else{
                  $(".search-null").slideUp("500");
                  $(".oaDepartSearch").slideDown("500");
	        	  var childDep = rs[0]._childDepartments.length;
	        	  var nowUser = rs[0]._users.length;

	        	  var nametop = rs[0]._addrss;

    			  if(""==nametop||null==nametop){
    				  nametop="抱歉，该部门还没有添加地址哦";
    			  }

	        	  deptThreeContent(rs[0]._fullname,rs[0]._phone,nametop);


	        	  if(nowUser>0){
	        		  for (var x = 0; x < nowUser; x++) {

	        			  var picpeoplexy = "pt";
		        		  var peoplesex = rs[0]._users[x].sex;
		        		  if('女' == peoplesex){
		        			  picpeoplexy = 'wm';
		        		  }

			    		  var $PersonAddressListInfo = $(PersonAddressListInfoHtml.replace("{lastname}",rs[0]._users[x].lastname).replace("{mobile}",rs[0]._users[x].mobile)
			    				  .replace("{jobtitle}",rs[0]._users[x].jobtitle).replace("{workcode}",rs[0]._users[x].workcode)
			    				  .replace("{departmentname}",rs[0]._users[x].departmentname).replace("{departmentphone}",rs[0]._users[x].departmentphone).replace("{picsex}",picpeoplexy));
			    		  $(".oaDepartSearch .departAdmin .departAdmin_tbody").append($PersonAddressListInfo);
			          }
	        	  }else{
	        		  $(".oaDepartSearch .departAdmin .departAdmin_tbody").empty();
	        	  }

	        	  if(childDep>0){
	        		  for (var x = 0; x < childDep; x++) {

	        			  var name = rs[0]._childDepartments[x]._addrss;

	        			  if(""==name||null==name){
	        				  name="抱歉，该部门还没有添加地址哦";
	        			  }

			    		  var $DeptAddressListInfo = $(DeptAddressListInfoHtml.replace("{_fullname}",rs[0]._childDepartments[x]._fullname)
			    				  .replace("{_phone}",rs[0]._childDepartments[x]._phone)
			    				  .replace("{_addrss}",name)
			    		  );
			    		  $(".oaDepartSearch .childDepart_table .childDepart_tbody").append($DeptAddressListInfo);
			          }
	        	  }else{
	        		  $(".oaDepartSearch .childDepart_table .childDepart_tbody").empty();
	        	  }
	        	  showContentPerson(nowUser);
	        	  showContentDept(childDep);
	          }
         },
         error: function (httpRequest) {
        	 // $(".oaDepartSearch").slideToggle("500");
             console.log("渲染部门信息查询方法失败！");
             showMsg("warn","系统维护中！");
         }
     });
}

function deptThreeContent(a1,a2,a3){
	$(".oaDepartSearch .childDepartName .oaDepartSearch-name").html(a1);
	  $(".oaDepartSearch .childDepartName .oaDepartSearch-departPhone").html(a2);
	  $(".oaDepartSearch .childDepartName .oaDepartSearch-address").html(a3);
}

function showContentPerson(number){
	if(number<5){
	    $('.oaDepartSearch .departAdmin').css('height','auto');
	    if(number==0){
	        $('.oaDepartSearch .departAdmin').css('display','none');
	    }else{
	        $('.oaDepartSearch .departAdmin').css('display','block');
	    }
	}else{
		$('.oaDepartSearch .departAdmin').css('display','block');
	    $('.oaDepartSearch .departAdmin').css('height','260px');
	}
}

function showContentDept(number){
	if(number<5){
	    $('.oaDepartSearch').find('.childDepart').css('height','auto');
	    if(number==0){
	        $('.oaDepartSearch .childDepart').css('display','none');
	    }else{
	        $('.oaDepartSearch .childDepart').css('display','block');
	    }
	}else{
		$('.oaDepartSearch .childDepart').css('display','block');
	    $('.oaDepartSearch').find('.childDepart').css('height','260px');
	}
}

/**
人员内容 pt   wm
*/
function returnAddressListPerson(){

		var AddressListInfoHtml = '<tr>' +
		'<td><img src="resources/img/user-{picsex}.jpg"></td>'+
		'<td>' +
		'<p><span>{lastname}</span><span>{workcode}</span><span>{mobile}</span>' +
		'</p>' +
		'<p><span>{jobtitle}</span><span>{departmentname}</span>' +
		'<span>{departmentphone}</span></p>' +
		'</td>' +
		'</tr>';
		return AddressListInfoHtml;
}

/**
部门内容
*/
function returnAddressListDept(){
		var AddressListInfoHtml = '<tr>' +
		'<td><div class="childDepart-td-box">'+
		'<p><span class="oa-name" onclick="submitThisDep(this)">{_fullname}</span>' +
		'<span class="departPhone">{_phone}</span></p>' +
		'<p><img src="resources/img/address-yellow.png">' +
		'<span>{_addrss}</span></p>' +
		'</div></td></tr>';
		return AddressListInfoHtml;
}


/**
 bumen  人员内容 pt   wm
*/
function returnAddressListPersonDept(){

		var AddressListInfoHtml = '<tr>' +
		'<td><img src="resources/img/user-{picsex}.jpg"></td>'+
		'<td>' +
		'<p><span>{lastname}</span><span>{workcode}</span><span>{mobile}</span>' +
		'</p>' +
		'<p><span>{jobtitle}</span>' +
		'<span>{departmentphone}</span></p>' +
		'</td>' +
		'</tr>';
		return AddressListInfoHtml;
}

function submitThisDep(obj){
	var inDeptName = $(obj)[0].textContent;
	queryAddressListByDept(inDeptName,0);
}
